package cn.tedu.charging.order.repository;

import cn.tedu.charging.common.pojo.po.ChargingBillSuccessPO;
import cn.tedu.charging.order.mapper.SuccessBillMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class SuccessBillRepository {
    @Autowired
    private SuccessBillMapper successBillMapper;

    public Long countByBillId(String billId) {
        //select count(0) from charging_bill_success where bill_id=billId
        QueryWrapper queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("bill_id",billId);
        return successBillMapper.selectCount(queryWrapper);
    }

    public void save(ChargingBillSuccessPO po) {
        successBillMapper.insert(po);
    }

    public ChargingBillSuccessPO findByBillId(String orderNo) {
        //select * from charging_bill_success where bill_id=?
        QueryWrapper<ChargingBillSuccessPO> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("bill_id",orderNo);
        return successBillMapper.selectOne(queryWrapper);
    }

    public void updateStatus(String orderNo, int status) {
        //update charging_bill_success set status=? where bill_id=?
        UpdateWrapper updateWrapper=new UpdateWrapper();
        updateWrapper.setSql("bill_status="+status);
        updateWrapper.eq("bill_id",orderNo);
        successBillMapper.update(null,updateWrapper);
    }
}
